﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using com.qbengo.utility.nodepicker.entity;

namespace com.qbengo.utility.nodepicker.business
{
    /// <summary>
    /// EventBLL
    /// </summary>
    public partial class EventBLL
    {
        private readonly com.qbengo.utility.nodepicker.DAL.EventDao dal = new com.qbengo.utility.nodepicker.DAL.EventDao();
        public EventBLL()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int eventid)
        {
            return dal.Exists(eventid);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(com.qbengo.utility.nodepicker.entity.Event model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(com.qbengo.utility.nodepicker.entity.Event model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int eventid)
        {

            return dal.Delete(eventid);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string eventidlist)
        {
            return dal.DeleteList(eventidlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public com.qbengo.utility.nodepicker.entity.Event GetModel(int eventid)
        {

            return dal.GetModel(eventid);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public com.qbengo.utility.nodepicker.entity.Event GetModelByCache(int eventid)
        {

            string CacheKey = "EventBLLModel-" + eventid;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(eventid);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (com.qbengo.utility.nodepicker.entity.Event)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<com.qbengo.utility.nodepicker.entity.Event> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<com.qbengo.utility.nodepicker.entity.Event> DataTableToList(DataTable dt)
        {
            List<com.qbengo.utility.nodepicker.entity.Event> modelList = new List<com.qbengo.utility.nodepicker.entity.Event>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                com.qbengo.utility.nodepicker.entity.Event model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new com.qbengo.utility.nodepicker.entity.Event();
                    if (dt.Rows[n]["eventid"] != null && dt.Rows[n]["eventid"].ToString() != "")
                    {
                        model.eventid = int.Parse(dt.Rows[n]["eventid"].ToString());
                    }
                    if (dt.Rows[n]["venueid"] != null && dt.Rows[n]["venueid"].ToString() != "")
                    {
                        model.venueid = int.Parse(dt.Rows[n]["venueid"].ToString());
                    }
                    if (dt.Rows[n]["event_type_id"] != null && dt.Rows[n]["event_type_id"].ToString() != "")
                    {
                        model.event_type_id = int.Parse(dt.Rows[n]["event_type_id"].ToString());
                    }
                    if (dt.Rows[n]["event_category_id"] != null && dt.Rows[n]["event_category_id"].ToString() != "")
                    {
                        model.event_category_id = int.Parse(dt.Rows[n]["event_category_id"].ToString());
                    }
                    if (dt.Rows[n]["name"] != null && dt.Rows[n]["name"].ToString() != "")
                    {
                        model.name = dt.Rows[n]["name"].ToString();
                    }
                    if (dt.Rows[n]["desc"] != null && dt.Rows[n]["desc"].ToString() != "")
                    {
                        model.desc = dt.Rows[n]["desc"].ToString();
                    }
                    if (dt.Rows[n]["utc_from"] != null && dt.Rows[n]["utc_from"].ToString() != "")
                    {
                        model.utc_from = DateTime.Parse(dt.Rows[n]["utc_from"].ToString());
                    }
                    if (dt.Rows[n]["utc_to"] != null && dt.Rows[n]["utc_to"].ToString() != "")
                    {
                        model.utc_to = DateTime.Parse(dt.Rows[n]["utc_to"].ToString());
                    }
                    if (dt.Rows[n]["hours"] != null && dt.Rows[n]["hours"].ToString() != "")
                    {
                        model.hours = dt.Rows[n]["hours"].ToString();
                    }
                    if (dt.Rows[n]["pricing"] != null && dt.Rows[n]["pricing"].ToString() != "")
                    {
                        model.pricing = dt.Rows[n]["pricing"].ToString();
                    }
                    if (dt.Rows[n]["url_info"] != null && dt.Rows[n]["url_info"].ToString() != "")
                    {
                        model.url_info = dt.Rows[n]["url_info"].ToString();
                    }
                    if (dt.Rows[n]["url_link"] != null && dt.Rows[n]["url_link"].ToString() != "")
                    {
                        model.url_link = dt.Rows[n]["url_link"].ToString();
                    }
                    if (dt.Rows[n]["image_url"] != null && dt.Rows[n]["image_url"].ToString() != "")
                    {
                        model.image_url = dt.Rows[n]["image_url"].ToString();
                    }
                    if (dt.Rows[n]["organizer"] != null && dt.Rows[n]["organizer"].ToString() != "")
                    {
                        model.organizer = dt.Rows[n]["organizer"].ToString();
                    }
                    if (dt.Rows[n]["event_poi"] != null && dt.Rows[n]["event_poi"].ToString() != "")
                    {
                        model.event_poi = int.Parse(dt.Rows[n]["event_poi"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

